﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;

public partial class SYS_POPEDOM_SYS_PWD_EDIT : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitOtherUser();
        }
    }

    private void InitOtherUser()
    {
        //DataTable dt = CommonLib.BLL.SYS_USER.GetList("user_id='" + BS_LoginUserID + "'").Tables[0];
        //if (dt.Rows.Count > 0)
        //{
        //    exttxtf_other_user1.Text = dt.Rows[0]["other_user1"].ToString();
        //    exttxtf_other_pwd1.Text = dt.Rows[0]["other_pwd1"].ToString();

        //    exttxtf_other_user2.Text = dt.Rows[0]["other_user2"].ToString();
        //    exttxtf_other_pwd2.Text = dt.Rows[0]["other_pwd2"].ToString();

        //    exttxtf_other_user3.Text = dt.Rows[0]["other_user3"].ToString();
        //    exttxtf_other_pwd3.Text = dt.Rows[0]["other_pwd3"].ToString();
        //}
    }

    //保存密码
    [DirectMethod]
    public string SavePwd()
    {
        string result = "true";
        CommonLib.Model.SYS_USER oModel = new CommonLib.Model.SYS_USER();
        oModel = CommonLib.BLL.SYS_USER.GetModel(BS_LoginUserID);

        if (exttxt_OldPwd.Text != CommonLib.ComMon.StringCommon.StringDecode(oModel.USER_PASSWORD))
        {
            X.Msg.Alert("系统提示", "旧密码不正确!").Show();
            ClearFields();
            result = "false";
        }
        if (exttxt_NewPwd.Text != exttxt_NewPwd2.Text)
        {
            X.Msg.Alert("系统提示", "新密码和确认密码不一致!").Show();
            ClearFields();
            result = "false";
        }

        oModel.USER_PASSWORD = CommonLib.ComMon.StringCommon.StringEncode(exttxt_NewPwd2.Text); ;
        try
        {
            if (result == "true")
            {
                CommonLib.BLL.SYS_USER.Update(oModel);
            }
        }
        catch
        {
            result = "false";
            X.Msg.Alert("系统提示", "密码修改失败!").Show();
        }
        return result;
    }

    private void ClearFields()
    {
        exttxt_OldPwd.Text = "";
        exttxt_NewPwd.Text = "";
        exttxt_NewPwd2.Text = "";
    }
}
